//包含“自己”.h；包含"config_.h"

#include "NUMBER_Set_Key_Read.h"
#include "config_.h"

extern int Number_wei_array[] = {
  com8    ,//空的
  com7    ,//空的
  com6    ,//COM6   LED
  com1    ,//COM1   数码管
  com2    ,//COM2   数码管
  com3    ,//COM3   数码管
  com4    ,//COM4   数码管
  com5    //COM5   数码管
};

extern int Number_duan_array[] = {
  Number_0  ,//0    1110 1110   A BCDEF
  Number_1  ,//1    1000 1000
  Number_2  ,//2    1101 0110
  Number_3  ,//3    1101 1100
  Number_4  ,//4    1011 1000
  Number_5  ,//5    0111 1100
  Number_6  ,//6    0111 1110
  Number_7  ,//7    1100 1000
  Number_8  ,//8    1111 1110
  Number_9  ,//9    1111 1100
  Numb_non  //kong  0000 0000
};

extern int Fuhao_duan_array[] = {
  fuhao           ,//-    负号
  xiaoshudian     ,//.    小数点
  kong            ,// 空
  led_shang       ,// LED_上
  led_zhong       ,// LED_中
  led_xia         ,// LED_下
  led_1           ,// LED_1
  led_2           ,// LED_2
  led_3           ,// LED_3
  led_4           ,// LED_4
  led_5           // LED_5
};

long long_NUMBER_Set_Key_Read(long number,int led,int DP ,int bright)
{
  int dp = DP;
  int Key_val;
  int Led_state = led;
  long Number = number;
  long com[5] ;
  if(Number<10000){
    com[0] = Number_duan_array[10];
  }else{
    com[0] = Number/10000;
  }if(Number<1000){
    com[1] = Number_duan_array[10];
  }else{
    com[1] = (Number-10000*com[0])/1000;
  }if(Number<100){
    com[2] = Number_duan_array[10];
  }else{
    com[2] = (Number-10000*com[0]-1000*com[1])/100;
  }if(Number<10){
    com[3] = Number_duan_array[10];
  }else{
    com[3] = (Number-10000*com[0]-1000*com[1]-100*com[2])/10;
  }
  com[4] = (Number-10000*com[0]-1000*com[1]-100*com[2]-10*com[3]);
  int j = 0x10;
  for(int i = 0;i < 5;i ++){
    
    digitalWrite(chipSelectPin, LOW);
    SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE2));
    SPI.transfer(j);       //数字位
    if(dp == i){
      SPI.transfer(Number_duan_array[com[i]]|xiaoshudian);  //段
    }else{
      SPI.transfer(Number_duan_array[com[i]]);  //段
    }
    SPI.endTransaction();
    digitalWrite(chipSelectPin, HIGH);  
    
    j = j>>1;
    delayMicroseconds(bright) ;
  }  
  digitalWrite(chipSelectPin, LOW);
  SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE2));
  SPI.transfer(0x20);       //LED位 com6
  SPI.transfer(Led_state);  //段
  SPI.endTransaction();
  digitalWrite(chipSelectPin, HIGH);
  SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE2));
  Key_val = ~SPI.transfer(0x00);//读
  SPI.endTransaction();
  digitalWrite(chipSelectPin, LOW);

  return Key_val;
  
}